var express = require('express');
var router = express.Router();

const {
  renderAdmin,
  addAdmin,
  deleteAdmin,
  oneAdmin,
  updateAdmin,
  getMerchantList,
  freezeMerchant,
  unFreezeMerchant,
  getShopList,
  handleSuccess,
  handleFail
}=require('../service/adminService');
//渲染管理员列表
router.get('/getAdmin',async function(req,res,next){
  res.send(await renderAdmin());
})

//新增管理员
router.post('/addAdmin',async function(req,res,next){
  const admin = req.body;
  const data = await addAdmin(admin);
  res.send(data);
})

//删除管理员
router.post('/deleteAdmin',async function(req,res,next){
  const params = req.body;
  const data = await deleteAdmin(params);
  res.send(data);
})

//通过_id来获取一个管理员的数据
router.post('/oneAdmin',async function(req,res,next){
  const params = req.body;
  const data = await oneAdmin(params);
  res.send(data);
})

//修改管理员
router.post('/updateAdmin',async function(req,res,next){
  const data = await updateAdmin(req.body);
  res.send(data);
})

//渲染商人列表
router.get('/getMerchantList',async function(req,res,next) {
  const data = await getMerchantList();
  res.send(data);
})

//冻结商人
router.post('/freezeMerchant',async function(req,res,next) {
  const data = await freezeMerchant(req.body);
  res.send(data);
})

//解冻商人
router.post('/unFreezeMerchant',async function(req,res,next) {
  const data = await unFreezeMerchant(req.body);
  res.send(data);
})

//门店列表
router.get('/getShopList',async function(req,res,next) {
  const data = await getShopList();
  res.send(data);
})

//门店通过审核
router.post('/handleSuccess',async function(req,res,next) {
  const data = await handleSuccess(req.body);
  console.log(111,data);
  res.send({data});
})

//门店审核失败
router.post('/handleFail',async function(req,res,next) {
  const data = await handleFail(req.body);
  console.log(222,data);
  res.send({data});
})


module.exports = router;